package com.bright.ghj.overt.web.controller;

import com.bright.ghj.common.pojo.bo.RestResult;
import com.bright.ghj.overt.util.SecurityUtil;
import com.bright.ghj.overt.pojo.command.CollectPlatformCommand;
import com.bright.ghj.overt.service.CollectPlatformService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import javax.validation.constraints.NotBlank;

/**
 * @author Tz
 * @date 2024/01/22 15:03
 * @Description 数据中心 - 上传到廉政平台
 */
@RequestMapping("/collectPlatform")
@RestController
@Validated
@RequiredArgsConstructor
@Api(tags = "上传到廉政平台")
public class CollectPlatformController {

    private final CollectPlatformService collectPlatformService;

    @PreAuthorize("hasAnyAuthority('uploadCity') && hasAnyAuthority('isPermitAdmin')")
    @ApiOperation(value = "收集数据到廉政平台")
    @PostMapping("/collect")
    public RestResult collect(@RequestBody @Valid CollectPlatformCommand collectPlatformCommand) {
        collectPlatformCommand.setUsername(SecurityUtil.getLoginUser().getUsername());
        return RestResult.success(collectPlatformService.collectToGovernment(collectPlatformCommand));
    }

    @PreAuthorize("hasAnyAuthority('uploadCity') && hasAnyAuthority('isPermitAdmin')")
    @ApiOperation(value = "查看上传到廉政平台的情况")
    @GetMapping("/getCollectInfo")
    public RestResult getCollectInfo(@NotBlank(message = "keyword不能为空") String keyword) {
        // 根据异步消息的条件来查询情况
        return RestResult.success(collectPlatformService.getCollectInfo(keyword));
    }

}
